package com.example.learn_spring_boot3.interecepror;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class TestInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        System.out.println("TestInterceptor preHandle start");
//        System.out.println("query url: " + request.getRequestURI());
//        System.out.println("query method: " + request.getMethod());
//        // System.out.println("请求参数url: " + request.getQueryString());
//        // System.out.println("服务端口: " + request.getServerPort());
//        // System.out.println("协议: " + request.getProtocol());
//        // System.out.println("服务名称: " + request.getServerName());
//        // System.out.println("Content-Type: " + request.getHeader("Content-Type"));
//        // System.out.println("User-Agent: " + request.getHeader("User-Agent"));
//        // System.out.println("name: " + request.getParameter("name"));
//        // System.out.println("所有的params参数: " + request.getParameterMap());
//        System.out.println("TestInterceptor preHandle end");

        // 返回 true 继续往下执行
        // 返回 false 不继续执行
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        // System.out.println("postHandle");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        // System.out.println("afterCompletion");
    }
}
